<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Laravel</title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">

    <script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    <!-- Styles -->
    <style>
        html, body {
            background-color: #fff;
            color: #636b6f;
            font-family: 'Raleway', sans-serif;
            font-weight: 100;
            height: 100vh;
            margin: 0;
        }

        .full-height {
            height: 100vh;
        }

        .flex-center {
            align-items: center;
            display: flex;
            justify-content: center;
        }

        .position-ref {
            position: relative;
        }

        .top-right {
            position: absolute;
            right: 10px;
            top: 18px;
        }

        .content {
            text-align: center;
        }

        .title {
            font-size: 84px;
        }

        .links > a {
            color: #636b6f;
            padding: 0 25px;
            font-size: 12px;
            font-weight: 600;
            letter-spacing: .1rem;
            text-decoration: none;
            text-transform: uppercase;
        }

        .m-b-md {
            margin-bottom: 30px;
        }

        button {
            color: #636b6f;
            padding: 0 25px;
            font-size: 12px;
            font-weight: 600;
            letter-spacing: .1rem;
            text-decoration: none;
            text-transform: uppercase;
            border: 1px solid red;
        }

        .publisher button {
            border-color: #49be00;
        }
    </style>
</head>
<body>
<div class="flex-center position-ref full-height">
    <div class="content">
        <div class="title m-b-md">
            <?php
            $user = \Auth::user();
            $name = $user ? $user->name : '没有登陆';
            $avatar = $user ? $user->avatar : '';
            ?>
        </div>

        <div class="title">
            <img src="{{$avatar}}" height="100"/>
        </div>
        <div class="title m-b-md" style="font-size: 30px">{{$name}}</div>
        @if(auth()->user()->isPublisher())
            <div class="publisher">
                <button>已经是发布者</button>
            </div>
        @else
            <div class="create_publisher">
                <button id="create_publisher">成为信息发布者</button>
            </div>
        @endif
    </div>
</div>
<script type="application/javascript">
    $('#create_publisher').click(function () {
        var invite_code = prompt('请输入邀请码：', '');
        if (invite_code === null) {
            return;
        }

        if (!invite_code) {
            alert('请输入邀请码');
            return;
        }

        $.ajax({
            url: '/api/publisher/active',
            type: "PUT",
            data: {code: invite_code},
            success: function (data, textStatus) {
                window.location.reload()
            },
            error: function (jqXHR, textStatus, error_msg) {
                alert(jqXHR.responseJSON.message);
            }
        });
    });

</script>
</body>
</html>
